package com.group.patients.service.impl;

import com.group.commons.entity.patient.Patient;
import com.group.commons.util.ResponseInfo;
import com.group.commons.util.ResponseStatus;
import com.group.patients.dao.PatientDao;
import com.group.patients.service.MainService;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: user  <br/>
 * Date: 2022/6/7:16:04  <br/>
 * Description:
 */
@Service
public class MainServiceImpl implements MainService {
    @Resource
    private PatientDao patientDao;

    @Override
    public ResponseInfo<PageImpl<Patient>> getData(Patient patient, PageRequest pageRequest) {
        long total = this.patientDao.count(patient);
        List<Patient> patients = this.patientDao.queryAllData(patient, pageRequest);
        List<Integer> collect = patients.stream().map(id -> id.getId()).collect(Collectors.toList());
        List<Patient> patients1 = this.patientDao.makeUp(collect);
        return new ResponseInfo<PageImpl<Patient>>(200, "OK",
                new PageImpl<Patient>(patients1, pageRequest, total),
                ResponseStatus.SUCCESS);
    }
}
